package com.molichuxing.services.infrastructure.service.impl;

import com.molichuxing.services.infrastructure.bean.VehicleMakeBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.VehicleMakeMapper;
import com.molichuxing.services.infrastructure.dto.response.VehicleMakeDto;
import com.molichuxing.services.infrastructure.service.VehicleMakeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 车辆品牌 服务实现类
 * </p>
 *
 * @author
 * @since 2019-07-29
 */
@Service("vehicleMakeService")
public class VehicleMakeServiceImpl implements VehicleMakeService {

    @Resource
    private VehicleMakeMapper vehicleMakeMapper;

    @Override
    public VehicleMakeDto getVehicleMakeDtoById(Integer vehicleMakeId) {
        //根据颜色id 查询颜色
        VehicleMakeBean vehicleMakeBean = vehicleMakeMapper.getById(vehicleMakeId);
        return Convert.toVehicleMakeDto(vehicleMakeBean);
    }

    @Override
    public List<VehicleMakeDto> getVehicleMakeDtoByMainId(Integer vehicleMainMakeId) {
        List<VehicleMakeBean> result = vehicleMakeMapper.getByPId(vehicleMainMakeId);
        return Convert.toVehicleMakeDto(result);
    }

    @Override
    public List<VehicleMakeDto> getVehicleMakeDtoByIds(List<Integer> vehicleMakeIds) {
        if (null == vehicleMakeIds || vehicleMakeIds.size() == 0) {
            return null;
        }
        List<VehicleMakeDto> vehicleMakeResult = new ArrayList<>();
        for (Integer vehicleId : vehicleMakeIds) {
            VehicleMakeBean vehicleMakeBean = vehicleMakeMapper.getById(vehicleId);
            vehicleMakeResult.add(Convert.toVehicleMakeDto(vehicleMakeBean));
        }

        List<VehicleMakeDto> result = new ArrayList<>();
        //获取主品牌
        for (VehicleMakeDto vehicleMakeDto : vehicleMakeResult) {
            VehicleMakeBean vehicleMakeBean = vehicleMakeMapper.getById(vehicleMakeDto.getPid());
            result.add(Convert.toVehicleMakeDto(vehicleMakeBean));
        }
        return result;
    }

    @Override
    public List<VehicleMakeDto> getVehicleMakeDto(Integer isMainMake) {
        return Convert.toVehicleMakeDto(vehicleMakeMapper.getVehicleMakeList(isMainMake));
    }

    @Override
    public List<VehicleMakeDto> getVehicleMakeDto(Integer isMainMake, List<Integer> vehicleIds) {
        return Convert.toVehicleMakeDto(vehicleMakeMapper.getVehicleMakeListAndVerhicleId(isMainMake, vehicleIds));
    }

    @Override
    public List<VehicleMakeDto> getVehicleMakeByIds(List<Integer> vehicleMakeIds) {
        if (null == vehicleMakeIds || vehicleMakeIds.size() == 0) {
            return null;
        }
        List<VehicleMakeBean> vehicleMakeResult = vehicleMakeMapper.getByIds(vehicleMakeIds);
        return Convert.toVehicleMakeDto(vehicleMakeResult);
    }


}
